<template>
  <div>
    <Loading v-if="flag"></Loading>
    <div v-else  v-infinite-scroll="load">
      <div
        class="item"
        v-for="(item, index) in curList"
        :key="index"
        @click="goDetail(item)"
      >
        <div class="left">
          <img :src="item.movieposter" alt="" />
        </div>
        <div class="middle">
          <div>{{ item.name }}</div>
          <div v-if="type == 1">
            <span>观众评分: </span>
            <span class="grade">{{ (item.filmScore+"分") || "暂无数据" }}</span>
          </div>
          <div>主演: {{ item.actornames}}</div>
          <div>{{ item.areaCountry }} </div>
        </div>
        <div class="right">
          <span v-if="type == 1">购票</span>
          <span v-if="type == 2">预购</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import Loading from "@/components/Loading1";
import router from "@/router"
import { ref } from "@vue/reactivity";
import { watch } from "@vue/runtime-core";
let props = defineProps(["list", "type"]);
let emit=defineEmits(["myload"])
let curList = ref([]);
let flag = ref(true);

watch(()=>props.list, (val) => {
  console.log("watch",val);
  curList.value.push(...val);
  flag.value = false;
});

function goDetail(item) {
  console.log(item._id);
  router.push(`/film/${item._id}`);
}
function load() {
  emit("myload")
}


</script>

<style lang="less" scoped>
.item {
  margin-top: 15px;
  padding-bottom: 35px;
  display: flex;
  color: #797d82;
  font-size: 13px;
  border-bottom: 1px solid #ededed;
  margin-bottom: 43px;

  .left {
    width: 77px;
    height: 100px;
    margin-left: 20px;

    img {
      width: 66px;
      height: 100%;
    }
  }

  .middle {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 55%;
    margin-left: 5px;

    div:nth-of-type(1) {
      color: #191a1b;
      font-size: 16px;
    }

    div:nth-of-type(3) {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .right {
    width: 15%;
    display: flex;
    align-items: center;
    margin-right: 10px;
    margin-left: 10px;

    span {
      border: 1px solid #ff5f16;
      background: white;
      color: #ff5f16;
      border-radius: 2px;
      height: 25px;
      line-height: 25px;
      font-size: 13px;
      width: 50px;
      text-align: center;
    }
  }
}

.pingfen {
  color: red;
}

.comfilmlistdivall {
  margin-bottom: 80px;
}
</style>
